package com.liudadan.spring_ioc_06;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.cglib.proxy.Factory;

public class UserServiceFactoryBean implements FactoryBean<UserService> {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "UserServiceFactoryBean{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public UserService getObject() throws Exception {
        UserService userService = new UserService(name,age);
        return userService; //返回的是容器中d="userService"对应的实例
    }

    @Override
    public Class<?> getObjectType() {
        return UserService.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
